import { http } from "@/utils/http";
import { baseUrlApi } from "./utils";
import type {
  aqiMeasuredResultType,
  inspectorType,
  monitorType
} from "@/store/types";
import type { gridCityResult } from "./gridCity";
import type { gridProvinceResult } from "./gridProvince";
export type MeasuredResult = {
  code: number;
  message: string;
  data: {
    list: {
      aqiMeasuredResult: aqiMeasuredResultType;
      inspector: inspectorType;
      monitor: monitorType;
      aqiValue: number;
      gridProvince: gridProvinceResult;
      gridCity: gridCityResult;
    };
  };
};

export type otherData = {
  code: number;
  message: string;
  data: {
    list: {
      count: number;
      goodCount: number;
      provinceCoverage: number;
      cityCoverage: number;
    };
  };
};

export type aqiTrend = {
  code: number;
  message: string;
  data: {
    list: {
      month: string;
      count: number;
    };
  };
};

export type aqiDistribution = {
  code: number;
  message: string;
  data: {
    list: {
      aqiLevel: string;
      aqiLevelDes: string;
      aqiDistribution: number;
    };
  };
};

/**获取确认信息列表 */
export const getAqiMeasuredDetail = (data: {
  aqiMeasuredResultParam: {};
  pageSize: number;
  pageNum: number;
}) => {
  return http.request<MeasuredResult>(
    "post",
    baseUrlApi(
      "/result/getMeasuredResultDetail" +
        "?pageSize=" +
        data.pageSize +
        "&pageNum=" +
        data.pageNum
    ),
    {
      data: data.aqiMeasuredResultParam
    }
  );
};

/** 获取确认列表总页数 */
export const getMeasuredResultTotalPage = (data: {
  aqiMeasuredResultParam: {};
  pageSize: number;
}) => {
  return http.request<{ totalPage: number }>(
    "post",
    baseUrlApi(
      "/result/getMeasuredResultListTotalPage" + "?pageSize=" + data.pageSize
    ),
    {
      data: data.aqiMeasuredResultParam
    }
  );
};

/**根据反馈信息id获取确认信息 */
export const getAqiMeasuredDetailByFbId = (fbId: number) => {
  return http.request<MeasuredResult>(
    "get",
    baseUrlApi("/result/getMeasuredResultByFbId"),
    { params: { fbId: fbId } }
  );
};

/**获取省分组分项检查统计 */
export const listResultByProvinces = () => {
  return http.request<gridProvinceResult>(
    "post",
    baseUrlApi("/result/listProvinceGrouping")
  );
};

/**获取其他数据统计 */
export const listOtherData = () => {
  return http.request<otherData>("get", baseUrlApi("/result/getOtherData"));
};

/**获取aqi指数分布超标趋势 */
export const getAqiIndexTrend = () => {
  return http.request<aqiTrend>("get", baseUrlApi("/result/getAqiTrend"));
};

/**获取aqi指数级别分布 */
export const getAqiDistribution = () => {
  return http.request<aqiDistribution>(
    "get",
    baseUrlApi("/result/getAqiDistribution")
  );
};

/**根据insId获取确认信息任务列表 */
export const getAqiMeasuredTaskListByInsId = (insId: number) => {
  return http.request<MeasuredResult>(
    "get",
    baseUrlApi("/result/getMeasuredResultByInsId"),
    { params: { insId: insId } }
  );
};

/**更新确认信息 */
export const updateAqiMeasuredResult = (data: { aqiMeasuredResult: {} }) => {
  return http.request<number>(
    "post",
    baseUrlApi("/result/updateAqiMeasuredResult"),
    {
      data: data.aqiMeasuredResult
    }
  );
};
